<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<base href="http://ant.apache.org/ivy/history/latest-milestone/resolver/">
<link rel="stylesheet" type="text/css" href="http://ant.apache.org/ivy/style/style.css">
</head>
<body id="body">
<div>
<h1>Packager Resolver</h1>
<table class="resolver">
<tr><td class="title">Tag</td><td class="value">packager</td></tr>
<tr><td class="title">Handle latest</td><td class="value">yes with http urls (and apache server) and with file urls, no with other urls</td></tr>
<tr><td class="title">Handle publish</td><td class="value">no</td></tr>
</table>

<br/>
<p>
<span class="since">Since 2.0</span>.
</p>

<p>
This resolver accesses ivy files and "packaging instructions" from an online "packager" repository. "Packager" repositories contain no actual artifacts. To get the artifacts, the packaging instructions are downloaded from the repository and executed locally. These instructions specify additional resource(s) to download and how to create the artifacts from them, for example, by downloading a project's original distribution archive directly from their web site and extracting the desired artifacts.
</p>

<p>
The only packaging operations currently supported are downloading files, extracting files from archives, packaging files into archives, and moving and copying files. In the future more general operations may be supported, once appropriate security controls are in place.
</p>

<p>
Packager repositories allow the creation of Ivy repositories that require neither the participation of any of the modules' creators nor setting up a huge mirror site. One such repository on the web is <a href="http://ivyroundup.googlecode.com/">Ivy RoundUp</a>. Of course, private packager repositories are feasible as well.
</p>

<p>
The Packager resolver supports a "resource cache", where downloaded archives can be stored to avoid duplicate downloads. This cache is entirely separate from the <a href="../concept.html#cache">normal Ivy cache</a>: it is "private" to the Packager resolver, and it stores unmodified original software archives, not Ivy artifacts. See the <span class="ivy-att">resourceCache</span> attribute below for details.
</p>

<p>
The packaging instructions are contained in "packager.xml" in a simple XML format. At resolve time this file gets converted into a "build.xml" file via XSLT and then executed using <a href="http://ant.apache.org/">ant</a>. Therefore, ant must be available as an executable on the platform. The ant task executes in a separate process and so is not affected by properties, etc. that may be set in any existing ant environment in which Ivy is running. However, Ivy will define a few properties for convenience; see the "Properties" listed below.
</p>

<p>
For security reasons, the XSLT transform ensures that (a) all downloaded archives have verified SHA1 checksums (including cached resources); and (b) only a very limited set of ant tasks can be performed during the artifact "build" phase; currently these include move, copy, mkdir, zip, unzip, tar, and untar.
</p>

<p>
The Packager resolver is based on the <a href="url.html">URL resolver</a> and is configured similarly, except the artifact child tags specify where to find the packager.xml files, rather than the artifacts themselves.
</p>

<p>
Because the downloading and packaging process is relatively slow, it is important to use <a href="../concept.html#cache">Ivy's caching support</a> to avoid repeated execution of the packaging instructions.
</p>

<h1>Attributes</h1>
This resolver shares the <a href="../configuration/resolvers.html#common">common attributes</a> of standard resolvers.
<table class="ivy-attributes">
<thead>
    <tr><th class="ivy-att">Attribute</th><th class="ivy-att-desc">Description</th><th class="ivy-att-req">Required</th></tr>
</thead>
<tbody>
  <tr>
    <td>buildRoot</td>
    <td>Defines the root of the temporary build directory hierarchy</td>
    <td>Yes</td>
  </tr>
  <tr>
    <td>resourceCache</td>
    <td>Directory where downloaded resources should be cached</td>
    <td>No; defaults to none</td>
  </tr>
  <tr>
    <td>resourceURL</td>
    <td>Ivy pattern that specifies a base URL to use for downloading <i>all</i> resources; overrides the URLs in the packaging instructions</td>
    <td>No; defaults to none</td>
  </tr>
  <tr>
    <td>verbose</td>
    <td>True to run ant with the -verbose flag</td>
    <td>No; defaults to false</td>
  </tr>
  <tr>
    <td>quiet</td>
    <td>True to run ant with the -quiet flag</td>
    <td>No; defaults to false</td>
  </tr>
  <tr>
    <td>validate</td>
    <td>True if this resolver should validate (via XSD) the downloaded XML packaging instructions</td>
    <td>No; defaults to true</td>
  </tr>
  <tr>
    <td>preserveBuildDirectories</td>
    <td>True if this resolver should not delete the temporary build directories in which the ant tasks are executed (for debugging purposes)</td>
    <td>No; defaults to false</td>
  </tr>
</tbody>
</table>
<br />
<p>
Setting a resourceURL will cause the resolver to override the URLs for resources specified by the packaging instructions. Instead, all resources will be downloaded from an URL constructed by first resolving the resourceURL pattern into a base URL, and then resolving the resource filename relative to that base URL. In other words, the resourceURL pattern specifies the URL "directory", so it should always end in a forward slash.
</p>

<p>
If a resourceURL download fails, the resolver will fall back to the original URL from the packaging instructions.
</p>

<p>
Configure a resourceURL in situations where you don't want to rely on (or wait for) the web sites configured in the packaging instructions, and have access to a better (perhaps private) mirror site.
</p>

<h1>Child elements</h1>
<table class="ivy-children">
<thead>
    <tr><th class="ivy-chld">Element</th><th class="ivy-chld-desc">Description</th><th class="ivy-chld-card">Cardinality</th></tr>
</thead>
<tbody>
    <tr><td>ivy</td><td>Defines a pattern for ivy.xml files, using the pattern attribute</td>
    <td>1..n</td></tr>
    <tr><td>artifact</td><td>Defines a pattern for packager.xml files, using the pattern attribute</td>
    <td>1..n</td></tr>
</tbody>
</table>

<h1>Examples</h1>
<pre type="xml">
&lt;packager name="ivyroundup"
         buildRoot="${user.home}/.ivy2/packager/build"
         resourceCache="${user.home}/.ivy2/packager/cache"
         resourceURL="ftp://mirror.example.com/pub/resources/[organisation]/[module]/"&gt;
    &lt;ivy pattern="http://ivyroundup.googlecode.com/svn/trunk/repo/modules/[organisation]/[module]/[revision]/ivy.xml"/&gt;
    &lt;artifact pattern="http://ivyroundup.googlecode.com/svn/trunk/repo/modules/[organisation]/[module]/[revision]/packager.xml"/&gt;
&lt;/packager&gt;
</pre>
Defines a packager resolver which points to the <a href="http://ivyroundup.googlecode.com/">Ivy RoundUp</a> online repository. Builds will occur in a subdirectory of <code>${user.home}/.ivy2/packager/build</code> downloaded resources will be cached in <code>${user.home}/.ivy2/packager/cache</code> and the mirror site <code>ftp://mirror.example.com/pub/resources/[organisation]/[module]/ </code> will be tried first for all resources.

<h1>Packaging Instructions</h1>
<p>
The goal of the packaging instructions is to download the required archives, extract the artifacts, and put the artifacts into a subdirectory. Each artifact should be written to artifacts/[type]s/[artifact].[ext] when the ant build completes.
</p>

<p>
Below is an example of packaging instructions for <a href="http://testng.org/">TestNG 2.5</a>:
<pre type="xml">
&lt;packager-module version="1.0"&gt;

    &lt;property name="name" value="${ivy.packager.module}"/&gt;
    &lt;property name="version" value="${ivy.packager.revision}"/&gt;
    &lt;property name="zipname" value="${name}-${version}"/&gt;

    &lt;resource dest="archive" url="http://testng.org/${zipname}.zip" sha1="2ea19275dc17453306f8bb780fe6ef6e9af7756b"&gt;
        &lt;url href="http://mirror.example.com/archives/${zipname}.zip"/&gt;
        &lt;include name="${zipname}/src/main/**/*"/&gt;
        &lt;include name="${zipname}/src/jdk15/**/*"/&gt;
        &lt;include name="${zipname}/javadocs/**/*"/&gt;
        &lt;include name="${zipname}/*.jar"/&gt;
    &lt;/resource&gt;

    &lt;build&gt;

        &lt;!-- jar  --&gt;
        &lt;move file="archive/${zipname}/${zipname}-jdk14.jar" tofile="artifacts/jars/${name}-jdk14.jar"/&gt;
        &lt;move file="archive/${zipname}/${zipname}-jdk15.jar" tofile="artifacts/jars/${name}-jdk15.jar"/&gt;

        &lt;!-- source --&gt;
        &lt;zip destfile="artifacts/sources/${name}.zip"&gt;
            &lt;fileset dir="archive/${zipname}/src/main"&gt;
                &lt;include name="**/*.java"/&gt;
            &lt;/fileset&gt;
            &lt;fileset dir="archive/${zipname}/src/jdk15"&gt;
                &lt;include name="**/*.java"/&gt;
            &lt;/fileset&gt;
        &lt;/zip&gt;

        &lt;!-- javadoc --&gt;
        &lt;zip destfile="artifacts/javadocs/javadoc.zip"&gt;
            &lt;fileset dir="archive/${zipname}/javadocs"/&gt;
        &lt;/zip&gt;
    &lt;/build&gt;
&lt;/packager-module&gt;
</pre>
Of course, packaging instructions must produce artifacts consistent with those listed in the associated ivy.xml file.
</p>

<h1>Build-time properties</h1>
This resolver ensures following ant properties are defined when it executes the ant build task.
<table class="ivy-attributes">
<thead>
    <tr><th class="ivy-att">Property</th><th class="ivy-att-desc">Description</th>
</thead>
<tbody>
  <tr>
    <td>ivy.packager.organisation</td>
    <td>Organization of the ivy module whose artifacts are being built</td>
  </tr>
  <tr>
    <td>ivy.packager.module</td>
    <td>Module of the ivy module whose artifacts are being built</td>
  </tr>
  <tr>
    <td>ivy.packager.revision</td>
    <td>Revision of the ivy module whose artifacts are being built</td>
  </tr>
  <tr>
    <td>ivy.packager.branch</td>
    <td>Branch of the ivy module whose artifacts are being built</td>
  </tr>
  <tr>
    <td>ivy.packager.resourceCache</td>
    <td>The configured <span class="ivy-att">resourceCache</span> if any; otherwise not defined</td>
  </tr>
  <tr>
    <td>ivy.packager.resourceURL</td>
    <td>The resolved <span class="ivy-att">resourceURL</span> pattern if any; otherwise not defined</td>
  </tr>
</tbody>
</table>

<h1>Packager XML Elements</h1>
The packager.xml document element can contain the following child tags.
<table class="ivy-children">
<thead>
    <tr><th class="ivy-chld">Element</th><th class="ivy-chld-desc">Description</th><th class="ivy-chld-card">Cardinality</th></tr>
</thead>
<tbody>
  <tr>
    <td>property</td>
    <td>Set an ant property</td>
    <td>0..n</td>
  </tr>
  <tr>
    <td>resource</td>
    <td>Define a resource to download and (optionally) unpack</td>
    <td>0..n</td>
  </tr>
  <tr>
    <td>m2resource</td>
    <td>Define a Maven2 resource to download and (optionally) unpack</td>
    <td>0..n</td>
  </tr>
  <tr>
    <td>build</td>
    <td>Specify move, copy, and/or archiving ant tasks that ultimately result in each artifact being placed into artifacts/[type]s/[artifact].[ext]</td>
    <td>0..1</td>
  </tr>
</tbody>
</table>

<h1>Resource XML Elements</h1>
The resource XML tag supports the following attributes:
<table class="ivy-attributes">
<thead>
    <tr><th class="ivy-att">Attribute</th><th class="ivy-att-desc">Description</th><th class="ivy-att-req">Required</th></tr>
</thead>
<tbody>
  <tr>
    <td>url</td>
    <td>Primary URL for the resource</td>
    <td>Yes</td>
  </tr>
  <tr>
    <td>sha1</td>
    <td>SHA1 checksum of the resource</td>
    <td>Yes</td>
  </tr>
  <tr>
    <td>dest</td>
    <td>Defines the name of the subdirectory into which the artifact should be unpacked</td>
    <td>No; defaults to "archive"</td>
  </tr>
  <tr>
    <td>tofile</td>
    <td>Where to put the file directly; if present no extraction will be performed</td>
    <td>No; if present, "dest" is ignored</td>
  </tr>
  <tr>
    <td>filename</td>
    <td>Name of the file to download</td>
    <td>No; if not present, same as the last component of the URL</td>
  </tr>
  <tr>
    <td>type</td>
    <td>Type of archive: "zip", "jar", "war", "tar", "tgz", "tar.gz", "tar.bz2"</td>
    <td>No; if not present, will be automatically determined from the filename suffix</td>
  </tr>
</tbody>
</table>
<br />
The resource XML tag may contain child elements. An url tag with an href attribute specifies an alternate URL for the resource (see TestNG example above). Any other tags will be included as children of an automatically generated fileset tag.

<h1>Maven2 Resources</h1>
Special support is included for maven2 resources. For these resources, use the m2resource tag instead of the resource tag. Each m2resource tag specifies one or more artifacts that are downloaded from the Maven2 repository.

<h1>M2Resource XML Elements</h1>
The m2resource XML tag supports the following attributes:
<table class="ivy-attributes">
<thead>
    <tr><th class="ivy-att">Attribute</th><th class="ivy-att-desc">Description</th><th class="ivy-att-req">Required</th></tr>
</thead>
<tbody>
  <tr>
    <td>groupId</td>
    <td>Maven group ID</td>
    <td>No; defaults to ${ivy.packager.organisation}</td>
  </tr>
  <tr>
    <td>artifactId</td>
    <td>Maven artifact ID</td>
    <td>No; defaults to ${ivy.packager.module}</td>
  </tr>
  <tr>
    <td>version</td>
    <td>Maven version</td>
    <td>No; defaults to ${ivy.packager.revision}</td>
  </tr>
  <tr>
    <td>repo</td>
    <td>Maven repository URL</td>
    <td>No; defaults to http://repo1.maven.org/maven2/ </td>
  </tr>
</tbody>
</table>
<br />
Each m2resource XML tag must have one or more artifact tags that define the artifacts to directly download. The URL for each artifact is constructed automatically based on the attributes in the m2resource and artifact tags.

<h1>M2Resource Artifact Attributes</h1>
The artifact children of m2resource tags support the following attributes:
<table class="ivy-attributes">
<thead>
    <tr><th class="ivy-att">Attribute</th><th class="ivy-att-desc">Description</th><th class="ivy-att-req">Required</th></tr>
</thead>
<tbody>
  <tr>
    <td>ext</td>
    <td>Maven filename extension</td>
    <td>No; defaults to "jar"</td>
  </tr>
  <tr>
    <td>classifier</td>
    <td>Maven classifier (e.g., "sources", "javadoc")</td>
    <td>No; defaults to none</td>
  </tr>
  <tr>
    <td>sha1</td>
    <td>SHA1 checksum of the resource</td>
    <td>Yes</td>
  </tr>
  <tr>
    <td>dest</td>
    <td>Defines the name of the subdirectory into which the artifact should be unpacked</td>
    <td rowspan="2">Exactly one of "dest" or "tofile" must be supplied</td>
  </tr>
  <tr>
    <td>tofile</td>
    <td>Where to put the file; no extraction will be performed</td>
  </tr>
  <tr>
    <td>type</td>
    <td>Type of archive: "zip", "jar", "war", "tar", "tgz", "tar.gz", "tar.bz2"</td>
    <td>No; if not present, will be automatically determined from the filename suffix</td>
  </tr>
</tbody>
</table>
<br />
Below is an example of packaging instructions for the <a href="http://commons.apache.org/email/">Apache Commons Email</a> module. Note that no build tag is required because all of the maven2 artifacts are usable directly (i.e., without unpacking anything).
<pre type="xml">
&lt;packager-module version="1.0"&gt;
    &lt;m2resource&gt;
        &lt;artifact tofile="artifacts/jars/${ivy.packager.module}.jar" sha1="a05c4de7bf2e0579ac0f21e16f3737ec6fa0ff98"/&gt;
        &lt;artifact classifier="javadoc" tofile="artifacts/javadocs/javadoc.zip" sha1="8f09630f1600bcd0472a36fb2fa2d2a6f2836535"/&gt;
        &lt;artifact classifier="sources" tofile="artifacts/sources/source.zip" sha1="15d67ca689a792ed8f29d0d21e2d0116fa117b7e"/&gt;
    &lt;/m2resource&gt;
&lt;/packager-module&gt;
</pre>
</p>

</div>
</body>
</html>
